#include "IEngineComponent.h"
#include "IEngineComponentCollection.h"

long long int IEngineComponent::nextComponentId = 0;

void IEngineComponent::Initialize(EnginePointer<IEngineComponentCollection> components)
{
}

IEngineComponent* IEngineComponent::Deserialize(EnginePointer<ISerializerReadContext>& context)
{
	map<char*, IEngineComponentDeserializer, IEngineComponentStringCmp>* deserializers = IEngineComponentRegistry::getDeserializerMap();

	return (*deserializers)[context->CurrentType()](context);
}

IEngineComponentRegistry::IEngineComponentRegistry(char* type, IEngineComponentDeserializer deserializer)
{
	map<char*, IEngineComponentDeserializer, IEngineComponentStringCmp>* deserializers = getDeserializerMap();

	(*deserializers)[type] = deserializer;
}

map<char*, IEngineComponentDeserializer, IEngineComponentStringCmp>* IEngineComponentRegistry::getDeserializerMap()
{
	static map<char*, IEngineComponentDeserializer, IEngineComponentStringCmp>* deserializers = new map<char*, IEngineComponentDeserializer, IEngineComponentStringCmp>();

	return deserializers;
}